import { PureComponent } from 'react'

// 劫持生命周期
function logRenderTime(OriginCpn) {
  // 直接返回该类，类名可以直接省略
  return class extends PureComponent {
    UNSAFE_componentWillMount() {
      this.beginTime = new Date().getTime()
    }

    componentDidMount() {
      this.end = new Date().getTime()
      const interval = this.end - this.beginTime
      console.log(`当前${OriginCpn.name}页面花费了多少时间渲染：, ${interval}`)
    }

    render() {
      return <OriginCpn />
    }
  }
}

export default logRenderTime
